package com.zgkxzx.android.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.MotionEvent;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.zgkxzx.android.androidtest.R;
import com.zgkxzx.android.androidtest.R;


/**
 * 创建者: ysm
 * 创建时间: 2016-11-29
 * 描述： View 两行-右侧尖括号
 */

public class LineItemView extends LinearLayout {

    private String title;
    private Bitmap icon;


    TextView tvTitle;
    ImageView ivIcon;

    public LineItemView(Context context) {
        this(context, null);
    }

    public LineItemView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public LineItemView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        inflate(context, R.layout.item_line, this);
        TypedArray type = context.obtainStyledAttributes(attrs, R.styleable.LineView);
        title = type.getString(R.styleable.LineView_itemTitle);
        icon = BitmapFactory.decodeResource(getResources(), type
                .getResourceId(R.styleable.LineView_itemIcon,
                        R.mipmap.icon_alarm));
        type.recycle();
        setMinimumHeight((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 56, context.getResources().getDisplayMetrics()));
        init();
    }

    private void init() {
        tvTitle = (TextView) findViewById(R.id.title_two_line);
        if (!TextUtils.isEmpty(title))
            tvTitle.setText(title);

        ivIcon = (ImageView) findViewById(R.id.iv_icon);
        ivIcon.setImageBitmap(icon);
    }

    public void setTitle(String title) {
        this.title = title;
        tvTitle.setText(title);
    }

    public String getTitle() {
        return title;
    }

    public void setIconImageRes(int resId) {
        ivIcon.setImageResource(resId);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        return true;
    }
}
